﻿<UserControl x:Class="Waf.Writer.Presentation.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:c="clr-namespace:Waf.Writer.Presentation.Converters"
    xmlns:p="clr-namespace:Waf.Writer.Presentation.Properties"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:dd="clr-namespace:Waf.Writer.Presentation.DesignData"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleMainViewModel, IsDesignTimeCreatable=True}"
    d:DesignWidth="800" d:DesignHeight="400">

    <Grid x:Name="rootContainer">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ContentView">
                <VisualState x:Name="StartViewVisible">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="documentView">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Storyboard.TargetName="documentView">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="400"/>
                        </DoubleAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="documentView">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="DocumentViewVisible">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" Storyboard.TargetName="documentView">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="startView">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="startView">
                            <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <ContentControl x:Name="startView" Content="{Binding StartView}">
            <ContentControl.RenderTransform>
                <TranslateTransform/>
            </ContentControl.RenderTransform>
        </ContentControl>

        <TabControl x:Name="documentView" ItemsSource="{Binding DocumentViews}" SelectedItem="{Binding ActiveDocumentView}">
            <TabControl.RenderTransform>
                <TranslateTransform/>
            </TabControl.RenderTransform>
                
            <TabControl.ItemContainerStyle>
                <Style TargetType="TabItem">
                    <Setter Property="Header" Value="{Binding Content.DataContext}"/>
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock VerticalAlignment="Center">
                                    <TextBlock.Text>
                                        <MultiBinding Converter="{StaticResource TabFileNameConverter}">
                                            <Binding Path="Document.FileName"/>
                                            <Binding Path="Document.Modified"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                    </TextBlock>
                                    <Button Command="{Binding DataContext.FileService.CloseCommand, ElementName=rootContainer}" Content="{StaticResource CloseSmallImage}"
                                        Visibility="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}},
                                            Converter={StaticResource BoolToVisibilityConverter}}"
                                        Width="16" Height="16" BorderThickness="0"
                                        MinWidth="0" MinHeight="0" Padding="0" Margin="7,0,0,0">
                                        <Button.Template>
                                            <ControlTemplate TargetType="{x:Type Button}">
                                                <ContentPresenter Margin="{TemplateBinding Control.Padding}" 
                                                                HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                                VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                                                SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
                                                                ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                                                RecognizesAccessKey="True"
                                                                Content="{TemplateBinding ContentControl.Content}"/>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                </StackPanel>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TabControl.ItemContainerStyle>
        </TabControl>
    </Grid>
</UserControl>
